/**
|--------------------------------Copyright-------------------------------------|
|                                                                              |
|                      (C)Copyright 2019,Chen Yikuang                          |
|                                                                              |
|------------------------------------------------------------------------------|
|  FileName     : Motor.h
|  Version      : v1.0
|  Author       : Chen Yikuang
|  Date         : 2019-05-23
|  Libsupports  : STM32F10x_StdPeriph_Lib_V3.5.0
|  Description  :
|------------------------------declaration of end------------------------------|
 **/
#ifndef __MOTOR_H
#define __MOTOR_H
/*------------------------ I N C L U D E - F I L E S -------------------------*/
/***PUBLIC FOLDER***/
#include "bsp.h"	
#include "UserMath.h"
#include "bsp_motor.h"
/*------------------------- G L O B A L - T Y P E S --------------------------*/

typedef enum{
	One = 0,
}Motor_e;

typedef enum{
	motor_Stop = 0,
	motor_Clockwise ,
	motor_Anticlockwise ,
}MotorMode_e;

typedef struct{ 
	Motor_e        ID;
	MotorMode_e    Mode;
	GPIO_TypeDef*  GPIOx;
	uint16_t       GPIO_Pin_x;
	GPIO_TypeDef*  GPIOy;
	uint16_t       GPIO_Pin_y;
	incrementalpid_t MotorPID;
	//统计获取数值的次数
	int32_t getSpeedCNT;
}Motor_t;
/*------------------------ G L O B A L - M A C R O S -------------------------*/
extern Motor_t Motor[1];
/*------------------------ G L O B A L - D E F I N E S -----------------------*/

#define PwmMaxOut  7055//电机限制最大PWM输出
//直流减速电机 带编码器 L=22 所以减速比为1：10
#define Period_79Y  		15000*4
#define Period_49Y  		1560
//电机限制的最大目标速度
#define targetSpeedMax_49Y   90
//电机限制的最大目标速度
#define targetSpeedMax_79Y   5380
//轮子直径D=60mm
#define fDiameter  60
//1圈周长pi*D(mm)
#define fperimeterMM ((float)fDiameter*(float)M_PI)
//1圈周长(m)
#define fperimeterM  ((float)fperimeterMM*(float)0.001)
//每线多少米（米/线数）
#define unit_M_Count_79Y  ((float)(fperimeterM)/(float)(Period_79Y))
#define unit_M_Count_49Y  ((float)(fperimeterM)/(float)(Period_49Y))
	
/*----------- G L O C A L - F U N C T I O N S - P R O T O T Y P E S ----------*/
void Motor_Init(void);
void Motor_setSpeed(Motor_t* Motor,int32_t MotorSpeed);
void abs_limit_i(int *a, int ABS_MAX);
/******************************************************************************/
#endif  //  __MOTOR_H
/*------------------------------- FILE OF END --------------------------------*/



